home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
query1.fr_
/
query1.fr
Wrap
Text File
|
1995-07-05
|
7KB
|
244 lines
VERSION 4.00
Begin VB.Form frmMain
BackColor = &H00C0C0C0&
Caption = "Query User"
ClientHeight = 2790
ClientLeft = 1095
ClientTop = 1500
ClientWidth = 6720
BeginProperty Font
name = "MS Sans Serif"
charset = 0
weight = 700
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 3195
Left = 1035
LinkTopic = "Form1"
ScaleHeight = 2790
ScaleWidth = 6720
Top = 1155
Width = 6840
Begin VB.CommandButton cmdClose
Cancel = -1 'True
Caption = "&Close"
Height = 435
Left = 4020
TabIndex = 14
Top = 1980
Width = 1155
End
Begin VB.CommandButton cmdMove
Caption = ">|"
Height = 435
Index = 3
Left = 2640
TabIndex = 13
Top = 1980
Width = 495
End
Begin VB.CommandButton cmdMove
Caption = ">"
Default = -1 'True
Height = 435
Index = 2
Left = 2160
TabIndex = 12
Top = 1980
Width = 495
End
Begin VB.CommandButton cmdMove
Caption = "<"
Height = 435
Index = 1
Left = 1680
TabIndex = 11
Top = 1980
Width = 495
End
Begin VB.CommandButton cmdMove
Caption = "|<"
Height = 435
Index = 0
Left = 1200
TabIndex = 10
Top = 1980
Width = 495
End
Begin VB.TextBox txtPublisher
Height = 315
Left = 2640
TabIndex = 9
Top = 1380
Width = 3855
End
Begin VB.TextBox txtYearPublished
Height = 315
Left = 1320
TabIndex = 8
Top = 1380
Width = 735
End
Begin VB.TextBox txtISBN
Height = 315
Left = 1320
TabIndex = 5
Top = 960
Width = 2295
End
Begin VB.TextBox txtTitle
Height = 315
Left = 1320
TabIndex = 3
Top = 540
Width = 5175
End
Begin VB.TextBox txtAuthor
Height = 315
Left = 1320
TabIndex = 1
Top = 120
Width = 2595
End
Begin VB.Label Label5
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "by:"
Height = 195
Left = 2220
TabIndex = 7
Top = 1440
Width = 270
End
Begin VB.Label Label4
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Published:"
Height = 195
Left = 300
TabIndex = 6
Top = 1440
Width = 900
End
Begin VB.Label Label3
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "ISBN:"
Height = 195
Left = 300
TabIndex = 4
Top = 1020
Width = 510
End
Begin VB.Label Label2
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Title:"
Height = 195
Left = 300
TabIndex = 2
Top = 600
Width = 450
End
Begin VB.Label Label1
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Author:"
Height = 195
Left = 300
TabIndex = 0
Top = 180
Width = 630
End
End
Attribute VB_Name = "frmMain"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Private rs As Recordset
Private Sub Form_Load()
Dim db As DATABASE
Dim dbName As String
Dim qd As QueryDef
' Set the error handler
On Error GoTo LoadError
' Get the database name and open the database.
dbName = BiblioPath() ' BiblioPath is a function in READINI.BAS
Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
' Open the query definition
Set qd = db.QueryDefs("All Titles")
' Create a recordset, using the query definition
Set rs = qd.OpenRecordset()
' Display the first record
If rs.RecordCount > 0 Then
DisplayRecord
Else
MsgBox "The query returned no records", vbCritical
End
End If
Exit Sub
LoadError:
MsgBox Error$, vbCritical
End
End Sub
Sub DisplayRecord()
' Check each field in the recordset to make sure it is not null.
' If it is not null, update its corresponding control with the contents
' of the field. If it is null, clear its corresponding control.
If Not IsNull(rs![Author]) Then txtAuthor = rs![Author] Else txtAuthor = ""
If Not IsNull(rs![Title]) Then txtTitle = rs![Title] Else txtTitle = ""
If Not IsNull(rs![ISBN]) Then txtISBN = rs![ISBN] Else txtISBN = ""
If Not IsNull(rs![Year Published] _
) Then txtYearPublished = rs![Year Published] Else txtYearPublished = ""
If Not IsNull(rs![Company Name] _
) Then txtPublisher = rs![Company Name] Else txtPublisher = ""
End Sub
Private Sub cmdMove_Click(Index As Integer)
Const MOVE_FIRST = 0
Const MOVE_PREVIOUS = 1
Const MOVE_NEXT = 2
Const MOVE_LAST = 3
On Error GoTo MoveError
' Execute the requested operation. If the operation puts the record
' pointer past the beginning or end of the file, move to the first
' or last record, as appropriate.
Select Case Index
Case MOVE_FIRST
rs.MoveFirst
Case MOVE_LAST
rs.MoveLast
Case MOVE_PREVIOUS
rs.MovePrevious
If rs.BOF Then rs.MoveFirst
Case MOVE_NEXT
rs.MoveNext
If rs.EOF Then rs.MoveLast
End Select
' Display the current record.
DisplayRecord
Exit Sub
MoveError:
MsgBox Error$, vbExclamation
Exit Sub
End Sub
Private Sub cmdClose_Click()
End
End Sub